package com.andong.controller;


import com.andong.annotations.AccessControl;
import com.andong.domain.entity.SubjectVideo;
import com.andong.domain.pojo.PageResult;
import com.andong.domain.pojo.Result;

import com.andong.service.SubjectVideoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static com.andong.utils.SystemConstant.*;

/**
 * 科目二三视频表(SubjectVideo)表控制层
 *
 * @author makejava
 * @since 2024-02-13 21:34:50
 */
@RestController
@RequestMapping("/subjectVideo")
public class SubjectVideoController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectVideoService subjectVideoService;

    /**
     * 添加或修改视频
     * @param subjectVideo 视频对象
     * @return 结果
     * @author XHU_WHY     */
    @PostMapping("/add")
    @AccessControl(roles = {ADMIN, SUPER_ADMIN}, permission = "资料管理")
    public Result addOrUpdate(@RequestBody SubjectVideo subjectVideo) {
        return subjectVideoService.saveOrModify(subjectVideo);
    }

    /**
     * 条件分页查询
     * @param page 页码
     * @param pageSize 一页展示的条数
     * @param name 名称
     * @param type 考试类型
     * @param vehicleType 车辆类型
     * @return 结果
     * @author XHU_WHY     */
    @GetMapping("/list")
    @AccessControl(roles = {STUDENT, ADMIN, SUPER_ADMIN}, permission = "资料管理")
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String name, Integer type, Integer vehicleType) {
        PageResult pageResult = subjectVideoService.queryList(page, pageSize, name, type, vehicleType);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询
     * @param id 数据id
     * @return 结果
     * @author XHU_WHY     */
    @GetMapping("/{id}")
    @AccessControl(roles = {ADMIN, SUPER_ADMIN}, permission = "资料管理")
    public Result getById(@PathVariable Long id) {
        SubjectVideo subjectVideo = subjectVideoService.getById(id);
        return Result.success(subjectVideo);
    }

    /**
     * 批量删除视频
     * @param ids id列表
     * @return 结果
     * @author XHU_WHY     */
    @DeleteMapping("/{ids}")
    @AccessControl(roles = {ADMIN, SUPER_ADMIN}, permission = "资料管理")
    public Result deleteByIds(@PathVariable List<Long> ids){
        return subjectVideoService.deleteByIds(ids);
    }
}

